// 导入监控元素或组件是否在视口
import { useIntersectionObserver } from '@vueuse/core'
import { ref } from 'vue'
export function useObserve (apiFn) {
  const newRef = ref(null)
  const { stop } = useIntersectionObserver(
    newRef,
    ([{ isIntersecting }]) => {
      if (isIntersecting) {
        apiFn()
        stop()
      }
    },
    {
      // 阈值：0-1 =》设置为0，加速接口请求
      threshold: 0
    }
  )
  return { newRef }
}
